<?php
namespace Home\Controller;

use Common\Controller\HomeController;
use Think\Upload;

class ToolController extends HomeController
{
    /**
     * 上传图片
     * @author Mr.Alien
     * @return string
     */
    public function upload(){
        $upload = new Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
        $upload->savePath  =     ''; // 设置附件上传（子）目录
        // 上传文件
        $info   =   $upload->upload();
        if(!$info) {// 上传错误提示错误信息
            $data = array('status'=>0,'info'=>$upload->getError());
            echo json_encode($data);
        }else{// 上传成功
            $data = array('status'=>1,'info'=>"/Uploads/".$info['photo']['savepath'].$info['photo']['savename']);
            echo json_encode($data);
        }
    }
}